package com.zzcy.bt_print_plugin;


import java.util.Timer;
import java.util.TimerTask;


/**
 * 延迟定时器
 */
public class DelayTimer {
    private Timer timer = null;
    private TimerTask timerTask = null;

    public DelayTimer(int startTime) {
        if (timer == null) {
            timer = new Timer();
        }
        if (timerTask == null) {
            timerTask = new TimerTask() {
                @Override
                public void run() {
                    if (onTimer != null) {
                        onTimer.onTimer();
                    }
                }
            };
            timer.schedule(timerTask, startTime);
        }
    }

    public void cancel() {
        if (timer != null) {
            timer.cancel();
            timer = null;
        }
        if (timerTask != null) {
            timerTask.cancel();
            timerTask = null;
        }
    }

    private OnTimer onTimer;


    public interface OnTimer {
        void onTimer();
    }

    public void setOnTimer(OnTimer onTimer) {
        this.onTimer = onTimer;
    }

}
